<template>
  <div class="app-container">
    <div class="filter-container">
      <el-date-picker
        v-model="times"
        class="filter-item"
        start-placeholder="推送开始日期"
        end-placeholder="推送结束日期"
        style="width: 250px;"
        type="daterange"
        value-format="yyyy-MM-dd"
      />
      <el-select
        v-model="listQuery.pushPlatform"
        placeholder="平台"
        clearable
        style="width: 150px;"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      >
        <el-option style="width: auto" label="DaJinDai" value="DaJinDai">大金贷</el-option>
        <el-option style="width: auto" label="Rong360" value="Rong360">融360</el-option>
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
      <!-- <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
        新增
      </el-button> -->
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="tableData"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="推送时间" align="center" width="150">
        <template slot-scope="{row}">
          <span>{{ row.worktime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="推送平台" class-name="status-col" min-width="150">
        <template slot-scope="{row}">
          <span>{{ row.pushPlatform }}</span>
        </template>
      </el-table-column>
      <el-table-column label="推送成功数量" align="center" min-width="150">
        <template slot-scope="{row}">
          <span>{{ row.pushSuccess }}</span>
        </template>
      </el-table-column>
      <el-table-column label="推送失败数量" min-width="150" align="center">
        <template slot-scope="{row}">
          <span>{{ row.pushFail }}</span>
        </template>
      </el-table-column>
      <el-table-column label="等待推送数量" class-name="status-col" min-width="150">
        <template slot-scope="{row}">
          <span>{{ row.waitPush }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="handleUpdate(row)">
            详情
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="pushReport"
    />

  </div>
</template>

<script>
import { pushReport } from '@/api/user'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'PhoneUserindex',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableData: [],
      total: 0,
      tableKey: 0,
      listQuery: {
        current: 1,
        size: 10
      },
      times: [],
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '用户详情',
        create: '新增'
      },
      dialogPvVisible: false,
      pvData: [],
      rules: {
        type: [{ required: true, message: 'type is required', trigger: 'change' }],
        timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        username: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
      downloadLoading: false,
      listLoading: false,
      optionsCopy: [],
      options: [],
      value: ''
    }
  },
  created() {
    this.pushReport(this.listQuery)
  },
  methods: {
    // 获取用户列表
    async pushReport(listQuery) {
      const res = await pushReport(this.listQuery)
      this.tableData = res.data.data.records
      this.total = res.data.data.total
    },
    handleFilter() {
      this.listQuery.current = 1
      if (this.times == null) {
        this.listQuery.endTime = ''
        this.listQuery.startTime = ''
      } else if (this.times.length === 0) {
        this.listQuery.endTime = ''
        this.listQuery.startTime = ''
      } else {
        this.listQuery.endTime = this.times[1]
        this.listQuery.startTime = this.times[0]
      }
      this.pushReport(this.listQuery)
    },
    handleDelete(row, index) {
      this.$notify({
        title: '成功',
        message: '删除成功',
        type: 'success',
        duration: 2000
      })
      this.list.splice(index, 1)
    },
    getSortClass: function(key) {
      const sort = this.listQuery.sort
      return sort === `+${key}` ? 'ascending' : 'descending'
    }
  }
}
</script>

<style scoped>
</style>
